# ┌───────┐
# │ aliases │
# └───────┘

# Basic file operations
alias ll='ls -la'

# Editor aliases
alias v='nvim'
alias vv="NVIM_APPNAME=$NVIM_NOTES_NAME nvim"
alias nv='neovide'
alias e='emacsclient -t'
alias ec='emacsclient -c'

# Emacs configurations
alias emacs1='emacs -q -l ~/.emacs1.d/init.el'
alias emacs2='emacs -q -l ~/.emacs2.d/init.el'
alias emacs3='emacs -q -l ~/.emacs3.d/init.el'

# File managers
alias ra='ranger'
alias l=y  # yazi file manager

# Tmux
alias t='tmux'
alias ta='tmux attach'

# Development tools
alias g='lazygit'
alias jp='jupyter'
alias dot='cd ~/dotfile'
alias lv=lvim
alias z='zeditor'
alias ff='fastfetch'
alias pc='proxychains4'

# Navigation
alias c='z'  # zoxide

# Python
alias vpython='ipython --TerminalInteractiveShell.editing_mode=vi'
alias math="python ~/play/math1.py"

# Note taking
alias note='note'

# Package management (Linux)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
    alias in='sudo pacman -S'
    alias un='sudo pacman -Rns'
    alias up='sudo pacman -Syu'
    alias pl='pacman -Qs'
    alias pa='pacman -Ss'
    alias open='xdg-open'
fi

# Package management (macOS)
if [[ "$OSTYPE" == "darwin"* ]]; then
    alias in='brew install'
    alias un='brew uninstall'
    alias up='brew update && brew upgrade'
    alias pl='brew list'
    alias pa='brew search'
fi

# Proxy settings
alias enableproxy='export http_proxy=http://127.0.0.1:1087; export https_proxy=http://127.0.0.1:1087'
alias enableproxyMini='export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890'
alias disableproxy='unset http_proxy https_proxy'

# Enhanced tools if available
if command -v lsd &> /dev/null; then
    alias ls='lsd'
fi

# ┌──────────┐
# │ functions │
# └──────────┘

# Yazi file manager with cd
y() {
    local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
    yazi "$@" --cwd-file="$tmp"
    if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
        builtin cd -- "$cwd"
    fi
    rm -f -- "$tmp"
}

# LF file manager with cd
lfcd() {
    cd "$(command lf -print-last-dir "$@")"
}

# Navigate to notes directory
oo() {
    dir=$(find "$HOME" -maxdepth 1 \( -type d -o -type l \) \
        -iname '[0-9][0-9][0-9]-*note*' \
        -exec bash -c 'for d; do [[ -d "$d" ]] && echo "$d"; done' _ {} + \
        | sort | head -1)
    if [[ -d "$dir/sigma" ]]; then
        builtin cd "$dir/sigma"
    elif [[ -d "$dir" ]]; then
        builtin cd "$dir"
    else
        builtin cd "$HOME/note/sigma"
    fi
}

# Cheatsheet function
cs() {
    local tmpfile=$(mktemp)
    curl -sSL "https://gitee.com/funnyzak/cli-cheatsheets/raw/main/cheatsheet.sh" -o "$tmpfile" && chmod +x "$tmpfile" && "$tmpfile" "$@" && rm -f "$tmpfile"
}
